<!-- BubbleBrands.vue -->
<template>
  <view>
    <view>
      <scroll-view class="move_scroll-container" scroll-x>
        <view class="move_category-row" style="padding-left: 10px">
          <view
            v-for="(item, index) in categoryList"
            :key="index"
            class="move_category-item"
          >
            <image
              :src="item.imageUrl"
              class="move_category-image"
              mode="aspectFit"
            />
          </view>
        </view>
      </scroll-view>
    </view>

    <view style="width: 100%; background-color: #f4dcc8">
      <view class="bubble-container">
        <view class="bubble_title-box">
          <h1 class="bubble_title">这份挚礼送给？</h1>
          <p class="bubble_subtitle">可点击查看</p>
        </view>
        <view class="bubble_Bubble_qipao">
          <view
            v-for="(brand, index) in brands"
            :key="index"
            class="bubble_bubble"
            :class="{ bubble_active: brand.isActive }"
            :style="{
              top: brand.top + 'px',
              left: brand.left + 'px',
              width: brand.size + 'rpx',
              height: brand.size + 'rpx',
              backgroundColor: brand.bgColor || '#fff',
              animationDelay: brand.delay + 's',
              animationDuration: brand.duration + 's',
            }"
            @click="handleBubbleClick(index)"
          >
            <view class="bubble_brand-content">
              <view
                :class="[
                  'bubble_brand-name',
                  brand.textColor,
                  { 'text-white': brand.isActive },
                ]"
                :style="{
                  fontSize: brand.fontSize + 'rpx',
                  fontWeight: brand.fontWeight || 400,
                }"
                >{{ brand.name }}</view
              >
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="money_price-container">
      <view class="money_price-title">这份挚礼的价值?</view>
      <view class="money_price-bubbles">
        <view
          v-for="(price, index) in prices"
          :key="index"
          class="money_price-bubble"
          :class="{ 'money_price-active': price.isActive }"
          @click="handlePriceClick(index)"
        >
          {{ price.range }}
        </view>
      </view>
    </view>

    <view class="giftbox-gift-section">
      <!-- 顶部标题 -->
      <view class="giftbox-section-title">
        <image
          src="https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372548867568d30cae1d.png"
          mode="aspectFit"
          class="giftbox-title-img"
        />
      </view>

      <!-- 分类列表 -->
      <view class="giftbox-category-list">
        <view
          v-for="(category, index) in categories"
          :key="category.id"
          class="giftbox-category-item"
          :class="{ 'giftbox-last': index === categories.length - 1 }"
          @tap="handleCategoryClick(category)"
        >
          <image
            :src="category.image"
            :mode="'aspectFill'"
            class="giftbox-category-img"
          />
          <view class="giftbox-category-text">
            <text class="giftbox-title">{{ category.title }}</text>
            <text class="giftbox-subtitle">{{ category.englishTitle }}</text>
          </view>
        </view>
      </view>

      <!-- 查看更多按钮 -->
      <view class="giftbox-view-more" @tap="handleViewMore">
        <text>!!</text>
        <text style="color: #767676; font-size: 28rpx">查看更多</text>
      </view>
    </view>

    <view class="product-container">
      <view v-for="(item, index) in buyList" :key="index" class="product-item">
        <image :src="item.imageUrl" class="product-image" mode="aspectFit" />
        <view class="product-info">
          <view class="product-title"
            >臻味&鲜品屋-上新臻味&鲜品屋-上新上新上新臻味&鲜品屋-上新臻味&鲜品屋-上新上新</view
          >
          <view class="price-buy-container">
            <view class="price-section">
              <view class="price-stack">
                <text class="activity-label">活动价</text>
                <text class="product-price">
                  <text style="font-size: 12px">¥</text>
                  399</text
                >
              </view>
            </view>
            <view class="buy-button">
              <text>点击购买</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "BubbleBrands",
  data() {
    return {
      buyList: [
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/1733726902675692b67d527.png",
        },
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/1733726902675692b67d527.png",
        },
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/1733726902675692b67d527.png",
        },
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/1733726902675692b67d527.png",
        },
      ],
      categories: [
        {
          id: 1,
          title: "综合礼盒DIY",
          englishTitle: "Comprehensive Gift Box DIY",
          image:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372529067568c6a8d0ac.png",
        },
        {
          id: 2,
          title: "坚果",
          englishTitle: "Nut",
          image:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372529067568c6a8d0ac.png",
        },
        {
          id: 3,
          title: "海鲜水产",
          englishTitle: "Seafood",
          image:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372529067568c6a8d0ac.png",
        },
        {
          id: 4,
          title: "五谷杂粮",
          englishTitle: "Five Grains and Coarse Grains",
          image:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372529067568c6a8d0ac.png",
        },
        {
          id: 4,
          title: "五谷杂粮",
          englishTitle: "Five Grains and Coarse Grains",
          image:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372529067568c6a8d0ac.png",
        },
      ],
      prices: [
        { range: "100元以下", isActive: false },
        { range: "100-200元", isActive: false },
        { range: "200-300元", isActive: false },
        { range: "300-400元", isActive: false },
        { range: "500-800元", isActive: true },
        { range: "800元以上", isActive: false },
      ],
      categoryList: [
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372405467568796b749b.png",
        },
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372405467568796b749b.png",
        },
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372405467568796b749b.png",
        },
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372405467568796b749b.png",
        },
        {
          imageUrl:
            "https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/173372405467568796b749b.png",
        },
      ],
      brands: [
        {
          name: "孩童",
          top: 10,
          left: -10,
          size: 132,
          fontSize: 32,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
        {
          name: "老人",
          top: 30,
          left: 110,
          size: 132,
          fontSize: 28,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
        {
          name: "其他",
          top: 45,
          left: 200,
          size: 116,
          fontSize: 28,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
        {
          name: "合作伙伴",
          top: -5,
          left: 315,
          size: 140,
          fontSize: 28,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
        {
          name: "爱人",
          top: 75,
          left: 26,
          size: 168,
          fontSize: 48,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: true,
        },
        {
          name: "亲戚",
          top: 70,
          left: 360,
          size: 132,
          fontSize: 28,
          textColor: "text-black",
          fontWeight: 500,
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
        {
          name: "同事",
          top: 155,
          left: 110,
          size: 96,
          fontSize: 28,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
        {
          name: "领导",
          top: 130,
          left: 180,
          size: 116,
          fontSize: 24,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
        {
          name: "好友",
          top: 110,
          left: 270,
          size: 130,
          fontSize: 24,
          textColor: "text-black",
          bgColor: "#ffffff",
          delay: this.getRandomDelay(),
          duration: this.getRandomDuration(),
          isActive: false,
        },
      ],
    };
  },
  methods: {
    handleCategoryClick(category) {
      console.log("Category clicked:", category);
      // 可以使用 uni.navigateTo 进行页面跳转
      // uni.navigateTo({
      //   url: `/pages/category/detail?id=${category.id}`
      // })
    },
    handleViewMore() {
      console.log("View more clicked");
      // 处理查看更多逻辑
    },
    handlePriceClick(index) {
      this.prices = this.prices.map((price, i) => ({
        ...price,
        isActive: i === index,
      }));
    },
    getRandomDelay() {
      return Math.random() * 2;
    },
    getRandomDuration() {
      return 5 + Math.random() * 2;
    },
    handleBubbleClick(index) {
      this.brands = this.brands.map((brand, i) => ({
        ...brand,
        isActive: i === index,
      }));

      console.log(index, "123");
    },
  },
};
</script>
<style lang="scss" scoped>
.product-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 16px;
}

.product-item {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  padding: 12px;
  position: relative;
  min-height: 213px;
  background-image: url("https://safood-1317438654.cos.ap-guangzhou.myqcloud.com/tempImage/1733727432675694c84c6f8.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.product-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

.product-image {
  width: 132px;
  height: 106px;
  border-radius: 8px;
  position: relative;
  z-index: 2;
}

.product-info {
  padding: 8px 0;
  position: relative;
  z-index: 2;
}

.product-title {
  font-size: 14px;
  margin-bottom: 18px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  line-height: 1.3;
  color: #794628;
  width: 100%;
  max-width: 100%;
  min-height: calc(14px * 1.3);
  max-height: calc(14px * 1.3 * 2);
  box-sizing: border-box;

}

.price-buy-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.price-section {
  display: flex;
  align-items: flex-end;
  flex: 1;
  min-width: 0;
}

.price-stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.activity-label {
  font-size: 10px;
  color: #e06b6b;
  line-height: 1;
  margin-bottom: 2px;
}

.product-price {
  color: #d13e3e;
  font-size: 22px;
  font-weight: bold;
  line-height: 1;
}

//按钮
.buy-button {
  width: 82px;
  height: 32px;
  background: linear-gradient(148deg, #db5656 0%, #c41f1f 100%);
  border-radius: 16px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  z-index: 10;

  text {
    z-index: 12;
    font-size: 28rpx;
    color: #f9ddb3;
    line-height: 32px;
    text-align: center;
  }

  &::before {
    content: "";
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(
      125deg,
      rgba(224, 184, 121, 1),
      rgba(249, 221, 179, 1),
      rgba(234, 189, 156, 1)
    );
    border-radius: 18px;
    z-index: -1;
  }

  &::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: inherit;
    border-radius: 16px;
    z-index: 0;
  }
}
</style>
<style scoped lang="scss">
.giftbox-gift-section {
  max-width: 750rpx;
  margin: 0 auto;
  padding: 20rpx;
}

.giftbox-section-title {
  margin-bottom: 20rpx;
}

.giftbox-title-img {
  width: 100%;
  height: 80rpx; /* 根据实际图片调整高度 */
}

.giftbox-category-list {
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}

.giftbox-category-item {
  position: relative;
  height: 244rpx;
  overflow: hidden;
}

.giftbox-category-img {
  width: 100%;
  height: 100%;
}

.giftbox-category-text {
  position: absolute;
  left: 40rpx;
  bottom: 40rpx;
  color: white;
}

.giftbox-category-text .giftbox-title {
  font-size: 48rpx;
  display: block;
}

.giftbox-category-text .giftbox-subtitle {
  font-size: 32rpx;
  display: block;
  margin-top: 10rpx;
}

.giftbox-category-item.giftbox-last {
  height: 244rpx;
}

.giftbox-view-more {
  display: flex;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  color: #666;
}

.money_price-container {
  padding: 30rpx;
  background-color: #f4dcc8;
}

.money_price-title {
  text-align: center;
  font-size: 48rpx;
  color: #e67624;
  font-weight: bold;
  margin-bottom: 40rpx;
}

.money_price-bubbles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30rpx;
  padding: 0 20rpx;
}

.money_price-bubble {
  height: 140rpx;
  width: 140rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  border-radius: 50%;
  font-size: 28rpx;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  margin: 0 auto;
  padding: 10rpx;
}

.money_price-active {
  background: linear-gradient(180deg, #fbeee5 0%, #e67624 100%);
  color: #ffffff;
  transform: scale(1.05);
  padding: 10rpx;
}

.money_price-bubble:active {
  transform: scale(0.95);
}
.move_scroll-container {
  width: 100%;
  white-space: nowrap;
  background-color: #f4dcc8;
  overflow: visible;
}

.move_category-row {
  display: flex;
  align-items: center;
  padding: 20rpx 0;
  width: 100%;
  gap: 30rpx;
  padding-left: 10px;
}

.move_category-item {
  box-shadow: 6rpx 6rpx 4rpx 0rpx rgba(0, 0, 0, 0.3);
  flex: 0 0 150rpx;
  height: 150rpx;
  background: #f9f9f9;
  border-radius: 12rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.move_category-image {
  width: 132rpx;
  height: 132rpx;
}

.bubble_Bubble_qipao {
  position: absolute;
  top: 75rpx;
  width: 100%;
  background-color: #f4dcc8;
  transform-origin: top left;
}

.bubble-container {
  position: relative;
  width: 100%;
  height: 450rpx;
  background-color: #f4dcc8;
}

.bubble_title-box {
  text-align: center;
  padding: 20rpx;
  border-radius: 10rpx;
  background-color: #f4dcc8;
}

.bubble_title {
  color: #e67624;
  font-size: 48rpx;
  font-weight: 600;
}

.bubble_subtitle {
  color: #3d3d3d;
  font-size: 28rpx;
  padding: 10rpx;
}

.bubble_bubble {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2rpx 15rpx rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
  animation: float infinite;
  transform-origin: center;
}

.bubble_active {
  background: linear-gradient(180deg, #fbeee5 0%, #e67624 100%) !important;
}

.text-white {
  color: #ffffff !important;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-30rpx);
  }
}

.bubble_brand-content {
  text-align: center;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.bubble_brand-name {
  line-height: 1.3;
  margin-bottom: 2rpx;
}

.text-green {
  color: #00843d;
}

.text-#F4DCC8 {
  color: #e60012;
}

.text-blue {
  color: #0066cc;
}

.text-cyan {
  color: #00a0e9;
}

.text-black {
  color: #333333;
}

.text-orange {
  color: #ff6600;
}

.bubble_bubble:hover {
  transform: translateY(-3rpx);
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}

@media screen and (max-width: 375px) {
  .bubble_Bubble_qipao {
    transform: scale(0.9);
  }
}

@media screen and (max-width: 320px) {
  .bubble_Bubble_qipao {
    transform: scale(0.8);
  }
}

/* iPad Media Query */
@media screen and (min-width: 768px) and (max-width: 1024px) {
  .bubble_Bubble_qipao {
    transform: scale(1.5);
    top: 150rpx;
  }

  .bubble_bubble {
    transform-origin: center;
  }

  .bubble_title {
    font-size: 72rpx;
  }

  .bubble_subtitle {
    font-size: 36rpx;
  }
}
</style>
